package com.example.demo.address.web;

import com.example.demo.address.entity.Address;
import com.example.demo.address.service.AddressService;
import com.example.demo.utils.RespMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;
    /**
     * 查询所有收货地址
     * @return
     */
    @RequestMapping("/list")
    public RespMessage findList(Address address){
        List<Address> list = addressService.findList(address);
        return RespMessage.success("成功",list);
    }


    /**
     * 查询所有单个收货地址
     * @return
     */
    @RequestMapping("/get")
    public RespMessage findOne(String id){
        addressService.findOne(id);
        return RespMessage.success("成功");
    }

    /**
     * 删除单个收货地址
     * @return
     */
    @RequestMapping("/remove")
    public RespMessage remove(String id){
        addressService.remove(id);
        return RespMessage.success("成功");
    }

    /**
     * 添加收货地址
     * @return
     */
    @RequestMapping("/save")
    public RespMessage save(Address address){
        addressService.save(address);
        return RespMessage.success("成功");
    }

    /**
     * 修改收货地址
     * @return
     */
    @RequestMapping("/update")
    public RespMessage update(Address address){
        addressService.update(address);
        return RespMessage.success("成功");
    }

}
